
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    but: "加入会员",
    tab_index: 0
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    var openid = app.globalData.openid;
    that.setData({

      card_id: options.id
    })
    that.getcard();
  },

  getcard: function () {
    let that = this;
    var openid = app.globalData.openid;
    app.ihttpGet("https://www.58zltc.com/api.php/MyCard/getlinkcard/openid/" + openid + "/id/" + that.data.card_id, function (res) {
      console.log(res.data.count)
      that.setData({
        list: res.data.list,
        count: res.data.count,

      })
    })
  },
  backto: function (e) {
    wx.navigateBack({})
  },
  link: function (e) {
    var openid = app.globalData.openid;
    var id = e.currentTarget.dataset.id;
    var t = this
    app.ihttpGet("https://www.58zltc.com/api.php/Card/linkCard/openid/" + openid + "/id/" + id + '/card_id/' + t.data.card_id, function (res) {
      if (res.data.err_code) {
        wx.showToast({
          icon: "none",
          title: res.data.err_msg,
        })
        setTimeout(function () {
          t.getcard()
        }, 1000)
      } else {
        wx.showToast({
          title: res.data.err_msg,
        })
        t.getcard()
      }
    })
  },

  excel: function (e) {
    var openid = app.globalData.openid;
    var id = e.currentTarget.dataset.id;
    var t = this
    app.ihttpGet("https://www.58zltc.com/api.php/Card/excel/openid/" + openid + "/id/" + id + '/card_id/' + t.data.card_id, function (res) {
      if (res.data.err_code) {
        wx.showToast({
          icon: "none",
          title: res.data.err_msg,
        })
        setTimeout(function () {
          t.getcard()
        }, 1000)
      } else {
        wx.showToast({
          title: res.data.err_msg,
        })
        t.getcard()
      }
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  changeTab: function (e) {
    this.setData({
      tab_index: e.currentTarget.dataset.tab_index
    })
  }
})